<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script >
        window.onload=function(){
            var app4 = new Vue({
                el: '#app-4',
                methods: {
                    add: function () {
                        var x={name:this.username,age:this.age,time:this.Date()};
                        this.people.push(x);
                    },
                    removeall: function () {this.people.push(this.people=[])},
                    remove: function (index) {this.people.splice(index,1)
                    }
                },
                data: {
                    username:'',
                    age:'',
                    people: [
                        { name: 'llf',age:'13',time:new Date() },
                        { name: 'lf',age:'12',time:new Date() },
                    ]
                }
            })
        }
    </script>
</head>
<body>
<div id="app-4">
    <input v-model="username">
    <input v-model="age">
    <button v-on:click="add">添加</button>
    <button v-on:click="removeall">全部删除</button>
    <table border="1">
        <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
        <tr v-for='(people, index) in people'>
            <td>{{index+1}}</td>
            <td>{{people.name}}</td>
            <td>{{people.age}}</td>
            <td>{{people.time.getHours()+':'+ people.time.getMinutes()+':'+ people.time.getSeconds() }}</td>
            <td><button v-on:click="time">删除</button></td>
        </tr>
    </table>
</div>
</body>
</html>
